#include "NodePriorityQueue.h"

void NodePriorityQueue::Push(int node)
{
	assert(node != -1);
	if(m_NodeIndices.empty())
	{
		m_NodeIndices.push_back(node);
	}
	else
	{
		for (std::list<int>::iterator it= m_NodeIndices.begin();it != m_NodeIndices.end(); it++)
		{
			if(m_NodeCost[node]<m_NodeCost[*it])
			{
				m_NodeIndices.insert(it,node);
				return;
			}
		}
		m_NodeIndices.push_back(node);
	}
}
void NodePriorityQueue::Pop()
{
	m_NodeIndices.pop_front();
	
}
void NodePriorityQueue::Resort()
{
	std::list<int> indices;
	std::list<int>::iterator tmp;

	while (!m_NodeIndices.empty())
	{
		tmp=m_NodeIndices.begin();

		for(std::list<int>::iterator next = ++m_NodeIndices.begin();next !=m_NodeIndices.end();++next)
		{
			if(m_NodeCost[(*next)] < m_NodeCost[(*tmp)])
			{
				tmp=next;
			}
		}
		indices.push_back(*tmp);
		m_NodeIndices.erase(tmp);
	}

	m_NodeIndices = indices;
}

int NodePriorityQueue::Front()
{
	return m_NodeIndices.front();
}

unsigned int NodePriorityQueue::Size()
{
	return m_NodeIndices.size();
}
bool NodePriorityQueue::Empty()
{
	return m_NodeIndices.empty();
}